package SGEngine

import (
	//"fmt"
	"github.com/gl"
)

var (
	ACDraw *aCDraw
)

type aCDraw struct {
	Node
	MProgram   *Program
	RenderFunc func()
}

func createDrawRender() *aCDraw {
	Rdraw := new(aCDraw)
	Rdraw.Node = DefaultNode()

	Rdraw.MProgram = ACProgramMgr.GetProgram(PROGRAM_QUAD)
	Rdraw.NodeRender = Rdraw
	return Rdraw
}
func SetDrawFunc(drawfunc func()) {
	if ACDraw == nil {
		ACDraw = createDrawRender()
		AddChild(WinRoot.MainScene, ACDraw)
	}
	ACDraw.RenderFunc = drawfunc
}

func (a *aCDraw) Render() {
	a.RenderFunc()
}

func (c *aCDraw) LinWidth(width float32) {
	gl.LineWidth(width)
}
func (c *aCDraw) DrawLine(P1, P2 Vector3) {
	array := []float32{
		P1.X, P1.Y, P1.Z,
		P2.X, P2.Y, P2.Z,
	}
	c.MProgram.ProgramObject.Use()
	c.MProgram.ProgramObject.GetUniformLocation("inColor").Uniform4f(1, 0, 0, 0)
	c.MProgram.ProgramObject.GetAttribLocation("vPosition").AttribPointer(3, gl.FLOAT, false, 0, array)
	c.MProgram.ProgramObject.GetAttribLocation("vPosition").EnableArray()
	gl.DrawArrays(gl.LINES, 0, 2)
}
